/*爱卡卡信息查询平台*/

$(document).ready(function(e) {
	var ul = document.getElementsByTagName('ul')[0];

	$('#select_data').click(function(e) {
		if(ul.style.display == 'block') {
			ul.style.display = 'none';
		} else {
			ul.style.display = 'block';
		}
	});
	$('.shared_div').click(function(e) {
		document.getElementsByClassName('shared_div')[0].style.display = 'none';
	})

	$('.pengyou').click(function(e) {
		var sharedDiv = document.getElementsByClassName('shared_div')[0];
		var height = window.screen.height
		sharedDiv.style.display = 'block';
		sharedDiv.style.height = height + 'px';
	})

	// 搜索按钮点击事件
	$(".search_btn").click(function(e) {
		var searchType = document.getElementById('contentSpan').getAttribute("value");
		var searchContent = $('.search input').val();
		if(searchType == -1) {
			layer.alert("请选择查询类型");
			return;
		}
		if(searchContent.length <= 0) {
			layer.alert("请输入查询内容");
			return;
		}
		var index = layer.load(0, {
			shade: 0.5
		}); //0代表加载的风格，支持0-2
		if(searchType == 0) {
			var params = {
				"typed": searchType,
				"idCard": searchContent
			};
			$.ajax({
				url: "/thmlfApi/queryInfo",
				type: "POST",
				data: JSON.stringify(params),
				dataType: 'json',
				contentType: "application/json;charset=utf-8",
				success: function(result) {
					var resultDiv = document.getElementsByClassName('result')[0];
					var bottomDiv = document.getElementsByClassName('bottom_div')[0];

					if($('.result').length != 0) {
						$('.result span').remove();
						$('.result table').remove();
					}
					resultDiv.style.top = "420px";
					if(result.code === 0) {
						var result_str = '<span>&nbsp;&nbsp;&nbsp;查询结果</span>' +
							'<table border="0" frame="void" cellpadding="0" cellspacing="1" width="100%">' +
							'<tr>' +
							'<td class="tname" width="30%">身份</td>' +
							'<td class="tvalue" width="4000">' + (result.partner.identity != null ? result.partner.identity : "") + '</td>' +
							'</tr>' +
							'<tr>' +
							'<td class="tname">姓名</td>' +
							'<td class="tvalue">' + (result.partner.partnerName != null ? result.partner.partnerName : "") + '</td>' +
							'</tr>' +
							'<tr>' +
							'<td class="tname">地区</td>' +
							'<td class="tvalue">' + (result.partner.address != null ? result.partner.address : "") + '</td>' +
							'</tr>' +
							'<tr>' +
							'<td class="tname">编号</td>' +
							'<td class="tvalue">' + (result.partner.number != null ? result.partner.number : "") + '</td>' +
							'</tr>' +
							'<tr>' +
							'<td class="tname">合同有效期</td>' +
							'<td class="tvalue">' + (result.partner.expiryDate != null ? result.partner.expiryDate : "") + '</td>' +
							'</tr>' +
							'</table>"';
						resultDiv.innerHTML = result_str;
						resultDiv.style.display = 'block'
						bottomDiv.style.top = "685px";
						var body = document.getElementsByTagName('body')[0];
						body.style.backgroundSize = 'cover';
					} else {
						var result_str = '<span>&nbsp;&nbsp;&nbsp;查询结果</span>' +
							'<table border="0" frame="void" cellpadding="0" cellspacing="1" width="100%">' +
							'<tr>' +
							'<td class="tvalue" width="4000" style="color: red;">非常抱歉，没有查询到该合作商信息！</td>' +
							'</tr>';
						$(".result").append(result_str);
						resultDiv.style.display = 'block';
						bottomDiv.style.top = "550px";
						var body = document.getElementsByTagName('body')[0];
						body.style.backgroundSize = 'cover';
					}
					layer.close(index);
				},
				error: function() {
					layer.close(index);
					layer.alert("请求失败，请重试");
				}
			});

		} else if(searchType == 3) {
			// 讲师查询
			var urlStr = "/thmlfApi/lecture/query?ct=" + searchContent;
			$.ajax({
				type: "get",
				url: urlStr,
				success: function(result) {
					var resultDiv = document.getElementsByClassName('result')[0];
					var bottomDiv = document.getElementsByClassName('bottom_div')[0];

					if($('.result').length != 0) {
						$('.result span').remove();
						$('.result table').remove();
					}
					resultDiv.style.top = "420px";
					if(result.code == 0) {
						var type = "";
						switch(result.data.type) {
							case 1:
								type = "爱卡卡创业版初级讲师";
								break;
							case 2:
								type = "爱卡卡创业版中级讲师";
								break;
							case 3:
								type = "爱卡卡创业版高级讲师";
								break;
							case 4:
								type = "爱卡卡创业版专家级讲师";
								break;
						}
						var result_str = '<span>&nbsp;&nbsp;&nbsp;查询结果</span>' +
							'<table border="0" frame="void" cellpadding="0" cellspacing="1" width="100%">' +
							'<tr>' +
							'<td class="tname" width="30%">姓名</td>' +
							'<td class="tvalue" width="4000">' + (result.data.name != null ? result.data.name : "") + '</td>' +
							'</tr>' +
							'<tr>' +
							'<td class="tname">级别</td>' +
							'<td class="tvalue">' + type + '</td>' +
							'</tr>' +
							'<tr>' +
							'<td class="tname">证书编号</td>' +
							'<td class="tvalue">' + (result.data.certificateNumer != null ? result.data.certificateNumer : "") + '</td>' +
							'</tr>' +
							'<tr>' +
							'<td class="tname">所属公司</td>' +
							'<td class="tvalue">' + (result.data.company != null ? result.data.company : "") + '</td>' +
							'</tr>' +
							'<tr>' +
							'<td class="tname">证书有效期</td>' +
							'<td class="tvalue">' + (result.data.expiryDate != null ? result.data.expiryDate : "") + '</td>' +
							'</tr>' +
							'<tr>' +
							'<td class="tname">证书详情</td>' +
							'<td class="tvalue"><a href="' + result.data.fileUrl + '">查看详情</a></td>' +
							'</tr>' +
							'</table>"';
						resultDiv.innerHTML = result_str;
						resultDiv.style.display = 'block'
						bottomDiv.style.top = "725px";
						var body = document.getElementsByTagName('body')[0];
						body.style.backgroundSize = 'cover';
					} else {
						layer.alert(result.msg);
					}
					layer.close(index);
				},
				error: function(e) {
					layer.close(index);
					layer.alert("查询失败，请重试");
				},
				async: true
			});

		} else {
			var params = {
				"typed": searchType,
				"partnerName": searchContent
			};
			$.ajax({
				url: "/thmlfApi/queryInfo",
				type: "POST",
				data: JSON.stringify(params),
				dataType: 'json',
				contentType: "application/json;charset=utf-8",
				success: function(result) {
					var resultDiv = document.getElementsByClassName('result')[0];
					var bottomDiv = document.getElementsByClassName('bottom_div')[0];

					if($('.result').length != 0) {
						$('.result span').remove();
						$('.result table').remove();
					}
					resultDiv.style.top = "420px";
					if(result.code === 0) {
						var result_str = '<span>&nbsp;&nbsp;&nbsp;查询结果</span>' +
							'<table border="0" frame="void" cellpadding="0" cellspacing="1" width="100%">' +
							'<tr>' +
							'<td class="tname" width="30%">身份</td>' +
							'<td class="tvalue" width="4000">' + (result.partner.identity != null ? result.partner.identity : "") + '</td>' +
							'</tr>' +
							'<tr>' +
							'<td class="tname">合作商</td>' +
							'<td class="tvalue">' + (result.partner.partnerName != null ? result.partner.partnerName : "") + '</td>' +
							'</tr>' +
							'<tr>' +
							'<td class="tname">地区</td>' +
							'<td class="tvalue">' + (result.partner.address != null ? result.partner.address : "") + '</td>' +
							'</tr>' +
							'<tr>' +
							'<td class="tname">编号</td>' +
							'<td class="tvalue">' + (result.partner.number != null ? result.partner.number : "") + '</td>' +
							'</tr>' +
							'<tr>' +
							'<td class="tname">合同有效期</td>' +
							'<td class="tvalue">' + (result.partner.expiryDate != null ? result.partner.expiryDate : "") + '</td>' +
							'</tr>' +
							'</table>"';
						resultDiv.innerHTML = result_str;
						resultDiv.style.display = 'block'
						bottomDiv.style.top = "685px";
						var body = document.getElementsByTagName('body')[0];
						body.style.backgroundSize = 'cover';
					} else {
						var result_str = '<span>&nbsp;&nbsp;&nbsp;查询结果</span>' +
							'<table border="0" frame="void" cellpadding="0" cellspacing="1" width="100%">' +
							'<tr>' +
							'<td class="tvalue" width="4000" style="color: red;">非常抱歉，没有查询到该合作商信息！</td>' +
							'</tr>';
						$(".result").append(result_str);
						resultDiv.style.display = 'block';
						bottomDiv.style.top = "550px";
						var body = document.getElementsByTagName('body')[0];
						body.style.backgroundSize = 'cover';
					}
					layer.close(index);
				},
				error: function() {
					layer.close(index);
					layer.alert("请求失败，请重试");
				}
			});
		}
	});
});

// li点击选中
function liClick(e) {
	var text = e.innerHTML;
	var typed = e.getAttribute("value");
	var selectSpan = document.getElementById('contentSpan');
	//					layer.alert(text+"--"+selectSpan.innerHTML)
	selectSpan.innerHTML = text;
	selectSpan.setAttribute("value", typed);
	if(typed == 0) {
		$(".search>input").attr("placeholder", "请输入身份证号码");
	} else if(typed == 3) {
		$(".search>input").attr("placeholder", "请输入身份证或证书编号");
	} else {
		$(".search>input").attr("placeholder", "请输入注册公司的全称");
	}
	var ul = document.getElementsByTagName('ul')[0];
	ul.style.display = 'none';
	var sub = $('ul').children('li');
	for(var i = 0; i < sub.length; i++) {
		var li = sub[i];
		//			layer.alert(li);
		li.style.backgroundColor = 'rgb(34,34,34)';
		//			li.setAttribute('background','rgb(34,34,34)')
	}
	e.style.backgroundColor = 'rgb(245,153,9)';
}